package com.fxd.uitls;

/**
 * @auther fuxudong
 * @date 2021/1/25 - 10:36
 * 和事物相关的工具类，它包含了开启事物，提交事物，回滚事物和释放连接
 */
public class transactionManager {

    private connectionUtil conn;

    public void setConn(connectionUtil conn) {
        this.conn = conn;
    }

    //开启事物
    public void begin() {
        try {
            conn.getThreadConnection().setAutoCommit(false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //提交事物
    public void commit() {
        try {
            conn.getThreadConnection().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //回滚事物
    public void rollback() {
        try {
            conn.getThreadConnection().rollback();
            System.out.println("回滚执行了");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //释放连接
    public void release() {
        try {
            conn.getThreadConnection().close();//换回连接池中
            conn.removeconn();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
